package com.huike.business.service.impl;


import com.huike.business.domain.TbBusiness;
import com.huike.business.domain.TbBusinessTrackRecord;
import com.huike.business.mapper.TbBusinessMapper;
import com.huike.business.mapper.TbBusinessTrackRecordMapper;
import com.huike.business.service.ITbBusinessTrackRecordService;
import com.huike.clues.mapper.SysDictDataMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Arrays;
import java.util.List;

/**
 * 商机跟进记录Service业务层处理
 * 
 * @author wgl
 * @date 2021-04-28
 */
@Service
public class TbBusinessTrackRecordServiceImpl implements ITbBusinessTrackRecordService {

    @Autowired
    private TbBusinessMapper tbBusinessMapper;

    @Autowired
    private TbBusinessTrackRecordMapper tbBusinessTrackRecordMapper;

    @Autowired
    private SysDictDataMapper dictDataMapper;

    @Override
    public int insertTbBusinessTrackRecord(TbBusiness business, TbBusinessTrackRecord trackRecord) {
        tbBusinessMapper.updateTbBusiness(business);
        return tbBusinessTrackRecordMapper.insertTbBusinessTrackRecord(trackRecord);
    }

    @Override
    public List<TbBusinessTrackRecord> getBusinessTrackRecordService(Long id) {
        List<TbBusinessTrackRecord> businessTrackRecords = tbBusinessTrackRecordMapper.getBusinessTrackRecordService(id);
        for (TbBusinessTrackRecord record : businessTrackRecords) {
            String[] keys = record.getKeyItems().split(",");
            List<String> keysData = dictDataMapper.getKeysData(keys);
            record.setKeys(keysData);
        }
        return businessTrackRecords;
    }
}
